我們今天飛遠一點,來介紹一下 Istio。Istio 可以提供我們更好的 load balance 能力,特別是在使用 gRPC 連線時,當前版本的 Kubernetes 本身是無法對 gRPC 連線進行 load balance 的,我們需要自己實作 sidecar 來完成 load balance 的目的,而 Istio 正好提供了我們所需要的功能。
Istio makes it easy to create a network of deployed services with load balancing, service-to-service authentication, monitoring, and more, with few or no code changes in service code.
就如同官方所聲稱的一樣,它提供了我們一個較無痛低成本的方式,進行 load balance 或 service-to-service 的溝通,甚至可以對 mircoserives 的 flow 進行 tracing。

完成後應顯示
> istioctl install --set profile=demo
✔ Istio core installed
✔ Istiod installed
✔ Egress gateways installed
✔ Ingress gateways installed
✔ Installation complete
看一下我們先前裝部署的範例所在的 Namespace
> kubectl describe deployments.apps
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Tue, 29 Sep 2020 16:55:01 +0800
Labels:                 app=nginx
Annotations:            deployment.kubernetes.io/revision=1
Selector:               app=nginx
Replicas:               2 desired | 2 updated | 2 total | 2 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx:1.14.2
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-deployment-574b87c764 (2/2 replicas created)
Events:          <none>
依照我們在 Namespace : default 的部份,掛上 Istio sidecar
> kubectl label namespace default istio-injection=enabled
namespace/default labeled
掛上 Istio proxy 前
> kubectl get pods
NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-574b87c764-82cm2   1/1       Running   0          47h
nginx-deployment-574b87c764-pvkt7   1/1       Running   0          47h
掛上 Istio proxy 後
> > kubectl get pods
NAME                                READY     STATUS    RESTARTS   AGE
nginx-deployment-574b87c764-64jlq   2/2       Running   0          3m19s
nginx-deployment-574b87c764-95r7r   2/2       Running   0          3m19s
可以看到在我們完成部署後,原先 Pods 內的 containers 從 1/1 變成 2/2,這個多出來的 container 便是 Istio proxy container,負責跟 Istio Control Plane 進行溝通,完成服務發現、health check、 load balance 等工作。